#include "URLUtilities.h"
#include "Main.h"
#include <algorithm>

URLUtilities::URLUtilities(void)
{
}


URLUtilities::~URLUtilities(void)
{
}

string URLUtilities::Decode(string Input, bool Get)
{
	size_t Pos = Input.find("%");
	for(auto it = Input.begin(); it != Input.end(); ++it)
	{
		if(Get)
		{
			if((*it) == '+')
			{
				Input.replace(it, it+1, " ");
			}
			if((*it) == '%')
			{
				string Hex = std::string(it+1, it+3);
				transform(Hex.begin(), Hex.end(), Hex.begin(), ::tolower);
				int Dec;
				from_string<int>(Dec, Hex, std::hex);
				Hex = Dec;

				Input.replace(it, it+3, Hex.begin(), Hex.end());
			}
		}

	}
	return Input;
}
